home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / Turret.tpl < prev   
Encoding:
Text File  |  2001-07-16  |  6.4 KB  |  205 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. UIFIELDS
  7. {
  8. FIELD<         INT,attackRange,"Attack Range",500>;        // At what range do I start shooting?
  9. FIELD<         INT,withdrawRange,"Withdraw Range",750>;        // At what range do I withdraw from combat entirely?
  10. FIELD<          INT,piloting,"Piloting Skill",50>;            // Piloting skill
  11. FIELD<          INT,gunnery,"Gunnery Skill",50>;            // Gunnery skill/chance to hit
  12. FIELD<          FLOAT,minDelay,"Minimum fire Delay",1.0>;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  13. FIELD<          FLOAT,maxDelay,"Maximum fire Delay",2.0>;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  14. FIELD<          INT,eliteLevel,"Elite Level",60>;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  15.                                                     // and other things.  It indicates a general level of combat experience.
  16. FIELD<           INT,isShotRadius,"Is Shot Radius",120>;        // How far away from me will I detect an enemy shot?        
  17. FIELD<INT,    attackThrottle,"Percent throttle when in combat",80>;
  18. FIELD<INT,    tower,"Unit ID of the Turret Tower",-1>;
  19.  
  20.  
  21. }
  22.  
  23.  
  24. fsm Generic_Turret : integer;
  25.  
  26.  
  27. //------------------------------------------------------------------
  28.  
  29. // Generic_Turret:
  30. //   This shoots anything that comes near, but never moves.
  31. //   It can be used for turrets.
  32.  
  33. //------------------------------------------------------------------
  34.  
  35.  
  36.  
  37. //------------------------------------------------------------------
  38. //     Constants
  39. //------------------------------------------------------------------
  40.  
  41.     const
  42.         #include_ <content\ABLScripts\mwconst.abi>
  43.  
  44. //------------------------------------------------------------------
  45. //     Types
  46. //------------------------------------------------------------------
  47.  
  48.     type
  49.         #include_ <content\ABLScripts\mwtype.abi>
  50.     
  51.  
  52. //------------------------------------------------------------------
  53. //     Variables
  54. //------------------------------------------------------------------
  55.  
  56.     var
  57.         static integer            attackRange;        // At what range do I start shooting?
  58.         static integer            withdrawRange;        // At what range do I stop attacking?
  59.  
  60.         static ObjectID            turretTower;        // My control tower: if destroyed, I stop firing
  61.                                                     
  62.         static integer            piloting;            // Piloting skill
  63.         static integer            gunnery;            // Gunnery skill/chance to hit
  64.         static real                minDelay;            // Minimum amount of time I will wait between shots once a weapon is reloaded
  65.         static real                maxDelay;            // Maximum amount of time I will wait between shots once a weapon is reloaded
  66.         static integer             eliteLevel;            // Elite level.  This helps determine tactics, defensive manuevers, opportunity fire
  67.                                                     // and other things.  It indicates a general level of combat experience.
  68.  
  69.          static integer            isShotRadius;        // How far away from me will I detect an enemy shot?
  70.         static integer            findTypes;            // What kind of enemies to look for
  71.  
  72.         static integer             attackSound;        // The attack sound I play when I first attack
  73.         static integer             deathSound;            // The sound I play when I die
  74.         
  75.         static integer            mood;                // My default mood.
  76.  
  77.         static integer            takeOffDistance;    // My take-off distance if I'm an airplane (ignored if not an airplane)
  78.  
  79. //------------------------------------------------------------------
  80. //     Init: my initialization function
  81. //------------------------------------------------------------------
  82.  
  83. function Init;
  84.     code
  85.     
  86.         // Variables set by editor
  87.         attackRange        = <attackRange>;
  88.         withdrawRange    = <withdrawRange>;
  89.         takeOffDistance    = <takeOffDistance>;
  90.          piloting        = <piloting>;
  91.         gunnery            = <gunnery>;
  92.         minDelay        = <minDelay>;
  93.         maxDelay        = <maxDelay>;
  94.         eliteLevel        = <eliteLevel>;
  95.         isShotRadius    = <isShotRadius>;
  96.     attackThrottle    = <attackThrottle>;
  97.  
  98.         turretTower        = <tower>;
  99.  
  100.         takeOffDistance    = 150;
  101.         attackSound        = -1; // no sound
  102.         deathSound        = -1; // no sound
  103.         mood            = NEUTRAL_START;
  104.         findTypes        = FT_DEFAULT;
  105.  
  106. endfunction;
  107.  
  108. //------------------------------------------------------------------
  109. //    StartState: my initial state
  110. //------------------------------------------------------------------
  111.  
  112. state StartState;
  113.  
  114.     code
  115.         SetFiringDelay            (ME,minDelay,maxDelay);
  116.         SetIgnoreFriendlyFire    (ME,true);
  117.         SetIsShotRadius            (ME,isshotradius);
  118.         SetEntropyMood            (ME,mood);
  119.         SetCurMood                (ME,mood);
  120.         SetSkillLevel            (ME,piloting,gunnery,elitelevel);
  121.                 
  122.         if (orderTakeOff(takeOffDistance) == true) then
  123.             trans WaitState;
  124.         endif;
  125.  
  126. endstate;            
  127.  
  128. //------------------------------------------------------------------
  129. //    WaitState: wait for someone to come near
  130. //------------------------------------------------------------------
  131.  
  132. state WaitState;
  133.     code
  134.         if (FindEnemy(attackRange,findTypes)) then
  135.             trans AttackState;
  136.         endif;
  137.  
  138.         if (turretTower <> NO_UNIT) then
  139.             if (IsDead(turretTower) == true) then
  140.                 trans TowerGoneState;
  141.             endif;
  142.         endif;
  143.  
  144.         SetSensorVisibility(ME,FALSE);
  145.         OrderMoveLookOut;
  146. endstate;
  147.  
  148. //------------------------------------------------------------------
  149. //    AttackState: let's see what's around, and destroy it
  150. //------------------------------------------------------------------
  151.  
  152. state AttackState;
  153.     code
  154.         if (LeaveAttackState(withdrawRange)) then
  155.             OrderStopAttacking;
  156.             SetTarget(ME,NO_UNIT);
  157.             trans WaitState;
  158.         endif;
  159.  
  160.         if (turretTower <> NO_UNIT) then
  161.             if (IsDead(turretTower) == true) then
  162.                 trans TowerGoneState;
  163.             endif;
  164.         endif;
  165.  
  166.         if (attackSound <> -1) then    
  167.             PlaySoundOnce(attackSound);
  168.         endif;
  169.  
  170.         SetSensorVisibility(ME,TRUE);
  171.         OrderAttackTactic(TACTIC_SHOOT_ONLY,true);
  172.  
  173. endstate;
  174.  
  175. //------------------------------------------------------------------
  176. //    TowerGoneState: my control tower is destroyed; I can do nothing
  177. //------------------------------------------------------------------
  178.  
  179. state TowerGoneState;
  180.     code
  181.         SetTarget(ME,NO_UNIT);
  182.         OrderStopAttacking;
  183.         ClearMoveOrder(ME);
  184.         SetTargetDesirability(ME,-1);
  185.         SetSensorVisibility(ME,FALSE);
  186. endstate;
  187.  
  188. //------------------------------------------------------------------
  189. //    DeadState: OK, I kicked the bucket.
  190. //------------------------------------------------------------------
  191.  
  192. state DeadState;
  193.     code
  194.         if (deathSound <> -1) then    
  195.             PlaySoundOnce(deathSound);
  196.         endif;        
  197.  
  198.         orderDie;
  199.  
  200. endstate;
  201.  
  202.  
  203. endfsm.
  204.  
  205.